package com.doone.telmarket.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.doone.telmarket.domain.Service;
import com.doone.telmarket.domain.ServicePage;
import com.doone.telmarket.domain.ServicePageContent;
import com.doone.telmarket.domain.ServiceProduct;
import com.doone.telmarket.domain.ibator.ServiceClassify;
import com.doone.telmarket.domain.ibator.ServiceType;
import com.doone.telmarket.service.ServiceOperation;
import com.doone.telmarket.infrastructure.dao.ServiceDAO;
import com.doone.telmarket.infrastructure.dao.ServicePageContentDao;
import com.doone.telmarket.infrastructure.dao.ServicePageDAO;

/**
 * @package com.doone.telmarket.domain.ibator
 * @author 甘雨波
 * @description 增值业务操作服务层实现类
 * @date 2009-9-17
 */
@org.springframework.stereotype.Service("serviceOperation")
public class ServiceOperationImpl implements ServiceOperation {

	
	@Autowired
	private ServiceDAO serviceDao;
	
	@Autowired
	private ServicePageDAO servicePageDAO;
	
	@Autowired
	private ServiceProductOperation serviceProductOperation;
	
	
	@Autowired
	private ServicePageContentDao servicePageContentDao;
	
	
	
	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 根据类型获取增值业务
	 * @date 2009-9-23
	 */
	public List<Service> selectServiceByType(String serviceTypeId, String serviceClassifyId) {
		Service service = new Service();
		ServiceType serviceType = new ServiceType();
		ServiceClassify serviceClassify = new ServiceClassify();
		serviceType.setServiceTypeId(Integer.parseInt(serviceTypeId));
		serviceClassify.setServiceClassifyId(Integer.parseInt(serviceClassifyId));
		service.setServiceClassify(serviceClassify);
		service.setServiceType(serviceType);
		return serviceDao.getServiceList(service);
	}
	
	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 保存增值业务
	 * @date 2009-9-17
	 */
	public String saveService(ServicePage servicePage,String sessionId,String rootPath) {
		Service service = serviceDao.insertService(servicePage.getService());
		List<ServiceProduct> prolist = service.getProducts();
		for(int i =0;i<prolist.size();i++)
		{
			prolist.get(i).setService(service);
			serviceProductOperation.saveServiceProduct(prolist.get(i));
		}
		List<ServicePageContent> spcList = servicePage.getContents();
		for(int z =0;z<spcList.size();z++)
		{
			spcList.get(z).setServicePage(servicePage);
			servicePageContentDao.saveServicePageContent(spcList.get(z));
		}
		
		servicePage.setService(service);
		servicePageDAO.insertServicePage(servicePage);
		return "S";
	}
	
	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 根据ID查询增值业务
	 * @date 2009-9-17
	 */
	public Service selectServiceById(String serviceCode) {
		return serviceDao.selectServiceByPrimaryKey(new Integer(serviceCode));
	}
	
	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 删除增值业务
	 * @date 2009-9-17
	 */
	public int deleteServiceById(String id) {
		return serviceDao.deleteServiceById(new Integer(id));
	}
	
	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 删除增值业务PAGE对象
	 * @date 2009-9-17
	 */
	public ServicePage selectServicePageByServiceId(String serviceId) {
		return servicePageDAO.selectServicePageByPrimaryKey(new Integer(serviceId));
	}

	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 更新增值业务
	 * @date 2009-9-17
	 */
	public void updateService(ServicePage servicePage,String sessionId,String rootPath) {
		
		servicePageDAO.updateService(servicePage);
	}

	public List<Service> getAllService() {
		return serviceDao.getAllService();
	}
	
	
	
	

}
